<html>
<head><meta charset="utf-8"><title>arch volatile operations · t-lang/wg-unsafe-code-guidelines · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/index.html">t-lang/wg-unsafe-code-guidelines</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html">arch volatile operations</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="169118169"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169118169" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169118169">(Jun 27 2019 at 09:31)</a>:</h4>
<p>It was tangentially discussed that we could add volatile load/stores to core::arch with stronger guarantees. </p>
<p>This is a sketch of how that could look like: <a href="https://gist.github.com/gnzlbg/c8ef62c12e692a420face245c5df7123" target="_blank" title="https://gist.github.com/gnzlbg/c8ef62c12e692a420face245c5df7123">https://gist.github.com/gnzlbg/c8ef62c12e692a420face245c5df7123</a></p>



<a name="169153909"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169153909" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169153909">(Jun 27 2019 at 17:11)</a>:</h4>
<p>that's the tearing thing, right?<br>
the alternative is to do what C++ did: some kind of compiler-implemented <code>trait VolatileAccess { const DOES_NOT_TEAR: bool; }</code></p>



<a name="169154305"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169154305" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169154305">(Jun 27 2019 at 17:15)</a>:</h4>
<p><span class="user-mention" data-user-id="132920">@gnzlbg</span> what does "with side-effects that freezes its result" mean? in particular I am confused by the "side-effects" part</p>



<a name="169154360"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169154360" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169154360">(Jun 27 2019 at 17:16)</a>:</h4>
<p>is that any different from just "that freezes its result"?</p>



<a name="169154384"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169154384" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169154384">(Jun 27 2019 at 17:16)</a>:</h4>
<p>in particular, this should <em>not</em> have the side-effect of freezing whatever is in memory at that position</p>



<a name="169154391"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169154391" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169154391">(Jun 27 2019 at 17:16)</a>:</h4>
<p>side-effects is that it is an unknown function</p>



<a name="169154410"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169154410" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169154410">(Jun 27 2019 at 17:16)</a>:</h4>
<p>freeze is that the value that is loaded, is frozen</p>



<a name="169154448"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169154448" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169154448">(Jun 27 2019 at 17:17)</a>:</h4>
<p>like:</p>
<div class="codehilite"><pre><span></span><span class="p">{</span><span class="w"></span>
<span class="w">   </span><span class="kd">let</span><span class="w"> </span><span class="n">r</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">*</span><span class="n">ptr</span><span class="p">;</span><span class="w"></span>
<span class="w">   </span><span class="n">freeze</span><span class="p">(</span><span class="n">r</span><span class="p">)</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</pre></div>



<a name="169154469"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169154469" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169154469">(Jun 27 2019 at 17:17)</a>:</h4>
<p>so even if the memory is undef, these never return undef</p>



<a name="169154482"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169154482" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169154482">(Jun 27 2019 at 17:17)</a>:</h4>
<p>oh, so that's:</p>
<p>16/32/64-bit atomic relaxed load from aligned <code>x</code><br>
- with side-effects ( -&gt; volatile)<br>
- that freezes its result.</p>
<p>that wasnt clear :D</p>



<a name="169154554"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169154554" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169154554">(Jun 27 2019 at 17:18)</a>:</h4>
<p>yeah, i should use "and" or commas :P</p>



<a name="169154565"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169154565" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169154565">(Jun 27 2019 at 17:18)</a>:</h4>
<p>I read it as "with (side-effects that freezes its result)"</p>



<a name="169154585"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169154585" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169154585">(Jun 27 2019 at 17:18)</a>:</h4>
<p>maybe "with side-effects and its result is frozen" ?</p>



<a name="169154634"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169154634" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169154634">(Jun 27 2019 at 17:19)</a>:</h4>
<p>I dont think many people will get the "with side-effects" part</p>



<a name="169154650"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169154650" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169154650">(Jun 27 2019 at 17:19)</a>:</h4>
<p>In the one-sentence version I'd just use the adjective "volatile"</p>



<a name="169154722"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169154722" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169154722">(Jun 27 2019 at 17:20)</a>:</h4>
<p>and then add a paragraph explaining that "volatile" basically means the read is speciifed to have side effects that are unknown to the compiler, which implies it cannot be duplicated or removed</p>



<a name="169154726"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169154726" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169154726">(Jun 27 2019 at 17:20)</a>:</h4>
<p>-&gt; MMIO</p>



<a name="169154736"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169154736" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169154736">(Jun 27 2019 at 17:20)</a>:</h4>
<p>or reordered across other volatile operations</p>



<a name="169154769"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169154769" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169154769">(Jun 27 2019 at 17:21)</a>:</h4>
<p>or reordered across syscalls or whatever</p>



<a name="169154786"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169154786" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169154786">(Jun 27 2019 at 17:21)</a>:</h4>
<p>when I started writing that, I used the term "synchronizes with volatile in the same thread of execution"</p>



<a name="169154802"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169154802" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169154802">(Jun 27 2019 at 17:21)</a>:</h4>
<p>no that's "atomic" terminology</p>



<a name="169154819"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169154819" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169154819">(Jun 27 2019 at 17:21)</a>:</h4>
<p>that is, there is no "happens before" across threads, but within the same thread</p>



<a name="169154831"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169154831" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169154831">(Jun 27 2019 at 17:22)</a>:</h4>
<p>which seems wrong here</p>



<a name="169154873"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169154873" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169154873">(Jun 27 2019 at 17:22)</a>:</h4>
<p>you can reorder some stuff around volatile loads</p>



<a name="169154878"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169154878" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169154878">(Jun 27 2019 at 17:22)</a>:</h4>
<p>speaking of which:<br>
"This operation is not atomic but it is data-race free."</p>
<p>here two meanings of the word "atomic" collide :/<br>
in my world, being data-race free is the definition of "atomic"</p>



<a name="169154895"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169154895" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169154895">(Jun 27 2019 at 17:22)</a>:</h4>
<p>if you are accessing the memory using volatile and non volatile operations</p>



<a name="169154908"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169154908" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169154908">(Jun 27 2019 at 17:22)</a>:</h4>
<p>sure, just like with other externally observable behavior</p>



<a name="169154924"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169154924" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169154924">(Jun 27 2019 at 17:23)</a>:</h4>
<p>you dont needs happens-before to specify that</p>



<a name="169155093"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169155093" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169155093">(Jun 27 2019 at 17:24)</a>:</h4>
<p>for the "not atomic but data-race-free", I'd say something like "this operation consists of multiple atomic operations -- so it causes no data races, but the result might be a mix of values written at different times".<br>
or maybe "this operation is not atomic in the sense that it does not behave transactional, but it is atomic in the sense that it does not cause data races"</p>



<a name="169155154"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169155154" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169155154">(Jun 27 2019 at 17:25)</a>:</h4>
<p>it kind of says that</p>
<blockquote>
<p>This operation is not atomic but it is data-race free.</p>
<p>The load from <code>x</code> is performed by (multiple) smaller or equally-wide volatile atomic <br>
loads in an unspecified order.</p>
</blockquote>



<a name="169155241"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169155241" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169155241">(Jun 27 2019 at 17:26)</a>:</h4>
<p>How about: The operation is not an atomic load, but it loads the memory in a data-race free way, by performing (potentially multiple) smaller or equally-wide volatile atomic loads in an unspecified order.</p>



<a name="169155308"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169155308" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169155308">(Jun 27 2019 at 17:27)</a>:</h4>
<p>what about "is not a single atomic load"?^^</p>



<a name="169155509"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169155509" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169155509">(Jun 27 2019 at 17:29)</a>:</h4>
<p>The operation is not necessarily a single atomic load. The memory is read in a data-race free way by performing either a single volatile atomic load, or multiple smaller volatile atomic loads in an unspecified order .</p>



<a name="169155826"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169155826" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169155826">(Jun 27 2019 at 17:33)</a>:</h4>
<p>So <span class="user-mention" data-user-id="120791">@RalfJ</span>  i've updated the gist a bit.</p>



<a name="169155839"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169155839" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169155839">(Jun 27 2019 at 17:33)</a>:</h4>
<p>I think we could nail down the finer print, if this ever gets RFCed</p>



<a name="169155865"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169155865" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169155865">(Jun 27 2019 at 17:33)</a>:</h4>
<p>sounds good</p>



<a name="169155874"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169155874" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169155874">(Jun 27 2019 at 17:34)</a>:</h4>
<p>I think we could retrofit <code>read_volatile</code> to have these semantics</p>



<a name="169155916"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169155916" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169155916">(Jun 27 2019 at 17:34)</a>:</h4>
<p>what about this:</p>
<blockquote>
<p>that's the tearing thing, right?<br>
the alternative is to do what C++ did: some kind of compiler-implemented <code>trait VolatileAccess { const DOES_NOT_TEAR: bool; }</code></p>
</blockquote>



<a name="169155952"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169155952" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169155952">(Jun 27 2019 at 17:34)</a>:</h4>
<p>your approach shares the problem of the <code>Atomic*</code> types that e.g. doing it on a <code>(u8, u16)</code> requires some awful code</p>



<a name="169155962"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169155962" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169155962">(Jun 27 2019 at 17:34)</a>:</h4>
<p>what should implement the trait?</p>



<a name="169155979"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169155979" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169155979">(Jun 27 2019 at 17:35)</a>:</h4>
<p>everything that's small enough to be lowered to a single volatile atomic access</p>



<a name="169155986"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169155986" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169155986">(Jun 27 2019 at 17:35)</a>:</h4>
<p>note that because it freezes the result, it should have less problems than the atomics</p>



<a name="169155996"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169155996" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169155996">(Jun 27 2019 at 17:35)</a>:</h4>
<p>fair</p>



<a name="169156006"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169156006" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169156006">(Jun 27 2019 at 17:35)</a>:</h4>
<p>maybe we should do that for the atomics to..</p>



<a name="169156015"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169156015" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169156015">(Jun 27 2019 at 17:35)</a>:</h4>
<p>so only aligned pointers are supported right?</p>



<a name="169156016"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169156016" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169156016">(Jun 27 2019 at 17:35)</a>:</h4>
<p>that precludes "de-atomization" optimizations</p>



<a name="169156029"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169156029" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169156029">(Jun 27 2019 at 17:35)</a>:</h4>
<p>supported for what?</p>



<a name="169156034"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169156034" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169156034">(Jun 27 2019 at 17:35)</a>:</h4>
<p>like the current <code>read_volatile</code> is UB if the pointer is not aligned</p>



<a name="169156042"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169156042" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169156042">(Jun 27 2019 at 17:36)</a>:</h4>
<p>yes</p>



<a name="169156093"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169156093" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169156093">(Jun 27 2019 at 17:36)</a>:</h4>
<p>note that the last set of intrinsics in the gist, supports unaligned loads</p>



<a name="169156094"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169156094" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169156094">(Jun 27 2019 at 17:36)</a>:</h4>
<p>people asked for a <code>read_volatile_unaligned</code> but I am not sure if it was ever added</p>



<a name="169156119"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169156119" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169156119">(Jun 27 2019 at 17:36)</a>:</h4>
<p>looks like it was added as intrinsic but not exposed? weird</p>



<a name="169156127"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169156127" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169156127">(Jun 27 2019 at 17:36)</a>:</h4>
<p><a href="https://doc.rust-lang.org/nightly/core/intrinsics/fn.unaligned_volatile_load.html" target="_blank" title="https://doc.rust-lang.org/nightly/core/intrinsics/fn.unaligned_volatile_load.html">https://doc.rust-lang.org/nightly/core/intrinsics/fn.unaligned_volatile_load.html</a></p>



<a name="169156162"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169156162" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169156162">(Jun 27 2019 at 17:37)</a>:</h4>
<p>so if your pointer is unaligned, the chances that you get tearing are super high</p>



<a name="169156175"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169156175" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169156175">(Jun 27 2019 at 17:37)</a>:</h4>
<p>even on x86_64</p>



<a name="169156185"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169156185" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169156185">(Jun 27 2019 at 17:37)</a>:</h4>
<p>if an operation does not require alignment you should say that explicitly</p>



<a name="169156202"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169156202" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169156202">(Jun 27 2019 at 17:37)</a>:</h4>
<p>it's kind of the default to require alignment ;)</p>



<a name="169156229"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169156229" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169156229">(Jun 27 2019 at 17:38)</a>:</h4>
<p>ok so I should change the names in the gist</p>



<a name="169156256"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169156256" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169156256">(Jun 27 2019 at 17:38)</a>:</h4>
<p>anyway I am not saying I have a preference either way, just pointing out that C++ followed a different route</p>



<a name="169156303"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169156303" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169156303">(Jun 27 2019 at 17:38)</a>:</h4>
<p>i prefer to have aligned in the name, because that's something that the user should know about, unaligned means we accept everything</p>



<a name="169156309"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169156309" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169156309">(Jun 27 2019 at 17:38)</a>:</h4>
<blockquote>
<p>ok so I should change the names in the gist</p>
</blockquote>
<p>yes, we usually only add <code>unaligned</code> explicitly but not <code>aligned</code></p>



<a name="169156338"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169156338" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169156338">(Jun 27 2019 at 17:38)</a>:</h4>
<p>I understand the sentiment but it's now how any other API works, so users just have to learn that</p>



<a name="169156340"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169156340" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169156340">(Jun 27 2019 at 17:38)</a>:</h4>
<p>that feels a bit like adding a <code>_this_function_does_not_have_preconditions</code> :D</p>



<a name="169156370"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169156370" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169156370">(Jun 27 2019 at 17:39)</a>:</h4>
<p>but I'll change that, so naming aside, the trait</p>



<a name="169156378"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169156378" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169156378">(Jun 27 2019 at 17:39)</a>:</h4>
<p>that can work</p>



<a name="169156384"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169156384" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169156384">(Jun 27 2019 at 17:39)</a>:</h4>
<p>or you convince t-libs to deprecate <code>ptr::read</code> in favor of <code>ptr::read_aligned</code> :D</p>



<a name="169156409"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169156409" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169156409">(Jun 27 2019 at 17:39)</a>:</h4>
<p>but we need to implement it for types of certain layout</p>



<a name="169156419"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169156419" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169156419">(Jun 27 2019 at 17:39)</a>:</h4>
<p>yes it would be a weird trait</p>



<a name="169156421"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169156421" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169156421">(Jun 27 2019 at 17:39)</a>:</h4>
<p>so I don't know how we could do that</p>



<a name="169156522"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169156522" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169156522">(Jun 27 2019 at 17:40)</a>:</h4>
<p>an alternative might be a <code>const fn volatile_access_does_not_tear&lt;T&gt;() -&gt; bool</code></p>



<a name="169156527"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169156527" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169156527">(Jun 27 2019 at 17:40)</a>:</h4>
<p>maybe that makes more sense</p>



<a name="169156530"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169156530" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169156530">(Jun 27 2019 at 17:40)</a>:</h4>
<p>I think that such an API could be built on top of the core::arch intrinsics</p>



<a name="169156536"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169156536" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169156536">(Jun 27 2019 at 17:40)</a>:</h4>
<p>in a library</p>



<a name="169156537"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169156537" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169156537">(Jun 27 2019 at 17:40)</a>:</h4>
<p>and then it's easy to look at the layout</p>



<a name="169156563"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169156563" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169156563">(Jun 27 2019 at 17:40)</a>:</h4>
<p>depends if you want to support all Ts with the same layout as e.g. u8, or you are ok with u8</p>



<a name="169156597"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169156597" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169156597">(Jun 27 2019 at 17:41)</a>:</h4>
<p>like if you have a different type, you only need <code>*mut T as _</code> in the function call</p>



<a name="169156599"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169156599" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169156599">(Jun 27 2019 at 17:41)</a>:</h4>
<p>the implementation of a polymorphic <code>const fn</code> can juts look at the <code>TyLayout</code>, check the <code>Abi</code>, and work with that</p>



<a name="169156641"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169156641" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169156641">(Jun 27 2019 at 17:41)</a>:</h4>
<blockquote>
<p>like if you have a different type, you only need <code>*mut T as _</code> in the function call</p>
</blockquote>
<p>what do you mean?</p>



<a name="169156667"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169156667" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169156667">(Jun 27 2019 at 17:42)</a>:</h4>
<p>I don't think we need const fn, we need something like what <code>transmute</code> did, before it was <code>const fn</code> (although these should be const fn)</p>



<a name="169156730"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169156730" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169156730">(Jun 27 2019 at 17:42)</a>:</h4>
<p>...?</p>



<a name="169156734"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169156734" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169156734">(Jun 27 2019 at 17:42)</a>:</h4>
<p>i mean calling ,e.g., <code> volatile_load_u16</code></p>



<a name="169156749"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169156749" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169156749">(Jun 27 2019 at 17:42)</a>:</h4>
<p>I have no idea what you mean</p>



<a name="169156768"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169156768" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169156768">(Jun 27 2019 at 17:42)</a>:</h4>
<p>or what problem you are even talking about^^</p>



<a name="169156808"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169156808" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169156808">(Jun 27 2019 at 17:43)</a>:</h4>
<p>you mentioned that if we don't have a trait, user code would be weird for <code>(u8, u32)</code>, but it looks like this:</p>
<div class="codehilite"><pre><span></span><span class="kd">let</span><span class="w"> </span><span class="n">x</span>: <span class="p">(</span><span class="kt">u8</span><span class="p">,</span><span class="w"> </span><span class="kt">u32</span><span class="p">);</span><span class="w"></span>
<span class="kd">let</span><span class="w"> </span><span class="n">y</span>: <span class="o">*</span><span class="k">const</span><span class="w"> </span><span class="p">(</span><span class="kt">u8</span><span class="p">,</span><span class="w"> </span><span class="kt">u32</span><span class="p">)</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">&amp;</span><span class="n">x</span><span class="p">;</span><span class="w"></span>
<span class="kd">let</span><span class="w"> </span><span class="n">r</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">core</span>::<span class="n">arch</span>::<span class="n">volatile_load_u32</span><span class="p">(</span><span class="n">y</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="n">_</span><span class="p">);</span><span class="w"></span>
</pre></div>



<a name="169156845"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169156845" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169156845">(Jun 27 2019 at 17:43)</a>:</h4>
<p>but now <code>r</code> has the wrong type</p>



<a name="169156916"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169156916" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169156916">(Jun 27 2019 at 17:44)</a>:</h4>
<p>and also <code>x as _</code> gives me shivers^^</p>



<a name="169156930"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169156930" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169156930">(Jun 27 2019 at 17:44)</a>:</h4>
<p>raw ptr casts are already dangerous when they are fully spelled out...</p>



<a name="169156940"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169156940" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169156940">(Jun 27 2019 at 17:44)</a>:</h4>
<p>i mean, we could do a transmute</p>



<a name="169156946"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169156946" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169156946">(Jun 27 2019 at 17:44)</a>:</h4>
<p>internally</p>



<a name="169156976"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169156976" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169156976">(Jun 27 2019 at 17:45)</a>:</h4>
<p><code>core::arch::volatile_load_32(y);</code> would cast internally y to a <code>*const u32</code>, do the load, and transmute back to <code>T</code></p>



<a name="169156979"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169156979" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169156979">(Jun 27 2019 at 17:45)</a>:</h4>
<p><code>volatile_load_u32&lt;T&gt;(x: *const T) -&gt; T where mem::size_of::&lt;T&gt;() == 4</code>?</p>



<a name="169157002"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169157002" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169157002">(Jun 27 2019 at 17:45)</a>:</h4>
<p>yeah</p>



<a name="169157020"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169157020" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169157020">(Jun 27 2019 at 17:45)</a>:</h4>
<p>that would make <code>u32</code> a misnomer</p>



<a name="169157033"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169157033" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169157033">(Jun 27 2019 at 17:45)</a>:</h4>
<p>but, sure, many things one can try :D</p>



<a name="169157037"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169157037" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169157037">(Jun 27 2019 at 17:45)</a>:</h4>
<p>(I changed it above)</p>



<a name="169157045"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169157045" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169157045">(Jun 27 2019 at 17:45)</a>:</h4>
<p>but yeah</p>



<a name="169157051"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169157051" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169157051">(Jun 27 2019 at 17:45)</a>:</h4>
<p>I have another concern though: calling this a "relaxed" access</p>



<a name="169157060"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169157060" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169157060">(Jun 27 2019 at 17:45)</a>:</h4>
<p>I am not sure if that's correct</p>



<a name="169157066"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169157066" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169157066">(Jun 27 2019 at 17:46)</a>:</h4>
<p>i used that to save words</p>



<a name="169157125"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169157125" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169157125">(Jun 27 2019 at 17:46)</a>:</h4>
<p>but that has a very specific technical meaning</p>



<a name="169157135"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169157135" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169157135">(Jun 27 2019 at 17:46)</a>:</h4>
<p>and I dont think we want that</p>



<a name="169157136"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169157136" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169157136">(Jun 27 2019 at 17:46)</a>:</h4>
<p>otherwise I need wording about data-race freedom in the other variants</p>



<a name="169157160"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169157160" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169157160">(Jun 27 2019 at 17:46)</a>:</h4>
<p>well the accesses are atomic, and the ordering is relaxed (they don't synchronize)</p>



<a name="169157186"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169157186" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169157186">(Jun 27 2019 at 17:46)</a>:</h4>
<p><code> release_fence();relaxed_store(x, 4);</code> is "almost" the same as <code>release_store(x, 4);</code></p>



<a name="169157193"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169157193" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169157193">(Jun 27 2019 at 17:46)</a>:</h4>
<p>I dont think we want to guarantee that for volatile stores</p>



<a name="169157212"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169157212" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169157212">(Jun 27 2019 at 17:47)</a>:</h4>
<p>relaxed <em>does</em> synchronize when it is program-order-before a release fence</p>



<a name="169157259"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169157259" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169157259">(Jun 27 2019 at 17:47)</a>:</h4>
<p>well in some sense</p>



<a name="169157307"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169157307" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169157307">(Jun 27 2019 at 17:48)</a>:</h4>
<p>what I mean is that you can implement synchronization with relaxed accesses and fences</p>



<a name="169157329"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169157329" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169157329">(Jun 27 2019 at 17:48)</a>:</h4>
<p>and I dont know if we can guarnatee that you can implement synchronization with volatile accesses and fences.</p>



<a name="169157460"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169157460" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169157460">(Jun 27 2019 at 17:50)</a>:</h4>
<p>ah I got the order wrong, dang^^ (fixed above)</p>



<a name="169157519"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169157519" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169157519">(Jun 27 2019 at 17:50)</a>:</h4>
<p>so I thought that a relaxed load / store could be reordered across a release fence</p>



<a name="169157522"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169157522" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169157522">(Jun 27 2019 at 17:50)</a>:</h4>
<p>so the rule is something like: release-fence program-order-before relaxed store which is read-from a relaxed load which is program-order-before an acquire fence... then we have a happens-before between the fences</p>



<a name="169157534"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169157534" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169157534">(Jun 27 2019 at 17:51)</a>:</h4>
<p>they can be reordered one way but not the other</p>



<a name="169157558"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169157558" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169157558">(Jun 27 2019 at 17:51)</a>:</h4>
<p>you can NOT move a relaxed store UP to before a release-fence</p>



<a name="169157577"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169157577" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169157577">(Jun 27 2019 at 17:51)</a>:</h4>
<p>because that would kill the synchronization in the rule I just mentioned</p>



<a name="169157665"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169157665" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169157665">(Jun 27 2019 at 17:52)</a>:</h4>
<p>(I hope I am getting the details right, but I know for sure that some pattern like this is legal for programmers, and hence a restriction for compilers)</p>



<a name="169157683"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169157683" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169157683">(Jun 27 2019 at 17:52)</a>:</h4>
<p>so you are right</p>



<a name="169157704"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169157704" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169157704">(Jun 27 2019 at 17:53)</a>:</h4>
<p>there's some explanation of this at <a href="http://plv.mpi-sws.org/fsl/base/paper.pdf" target="_blank" title="http://plv.mpi-sws.org/fsl/base/paper.pdf">http://plv.mpi-sws.org/fsl/base/paper.pdf</a>... at least that's the best kind of explanation for me, YMMV ;)</p>



<a name="169157750"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169157750" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169157750">(Jun 27 2019 at 17:53)</a>:</h4>
<p>a release_fence followed by a relaxed store is a release_store, and a relaxed_load followed by a acquire_fence is a acquire_load</p>



<a name="169157759"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169157759" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169157759">(Jun 27 2019 at 17:53)</a>:</h4>
<p>no that's not correct either</p>



<a name="169157837"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169157837" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169157837">(Jun 27 2019 at 17:54)</a>:</h4>
<p>aquire_load sorry</p>



<a name="169157845"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169157845" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169157845">(Jun 27 2019 at 17:54)</a>:</h4>
<p>no thats not it</p>



<a name="169157855"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169157855" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169157855">(Jun 27 2019 at 17:54)</a>:</h4>
<p>a release-fence followed by  a relaxed-store will build up happens-before <em>only</em> with something followed by an acquire fence</p>



<a name="169157878"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169157878" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169157878">(Jun 27 2019 at 17:54)</a>:</h4>
<p>whereas a release-store will build-up happens-before <em>only</em> with an acquire load <em>to the same location</em></p>



<a name="169157938"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169157938" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169157938">(Jun 27 2019 at 17:55)</a>:</h4>
<p>a relaxed_load followed by an acquire_fence is an acquire_load</p>



<a name="169157948"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169157948" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169157948">(Jun 27 2019 at 17:55)</a>:</h4>
<p>no</p>



<a name="169157970"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169157970" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169157970">(Jun 27 2019 at 17:55)</a>:</h4>
<p>let me type out the counterexample</p>



<a name="169157984"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169157984" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169157984">(Jun 27 2019 at 17:55)</a>:</h4>
<p>(you are right in x86/ARM but not in C/C++/Rust)</p>



<a name="169158014"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169158014" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169158014">(Jun 27 2019 at 17:56)</a>:</h4>
<p>(well for x86 it's moot because TLS but whatever^^)</p>



<a name="169158161"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169158161" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169158161">(Jun 27 2019 at 17:56)</a>:</h4>
<p>coming back to your point</p>



<a name="169158205"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169158205" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169158205">(Jun 27 2019 at 17:57)</a>:</h4>
<p>if we use the term atomic relaxed, then the fences would synchronize with volatile operations, and we don't want that</p>



<a name="169158208"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169158208" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169158208">(Jun 27 2019 at 17:57)</a>:</h4>
<p>Thread 1:</p>
<div class="codehilite"><pre><span></span>data = 32; // non-atomic
fence_release();
store_relaxed(flag, 1);
</pre></div>


<p>Thread 2:</p>
<div class="codehilite"><pre><span></span>while load_relaxed(flat) == 0 { }
fence_acquire();
print(data); // non-atomic
</pre></div>



<a name="169158217"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169158217" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169158217">(Jun 27 2019 at 17:57)</a>:</h4>
<p>this code is okay and data-race-free</p>



<a name="169158262"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169158262" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169158262">(Jun 27 2019 at 17:58)</a>:</h4>
<p>now after replacing the relaxed-store-followed-by-release-fence we have<br>
Thread 1:</p>
<div class="codehilite"><pre><span></span>data = 32; // non-atomic
store_release(flag, 1);
</pre></div>


<p>Thread 2:</p>
<div class="codehilite"><pre><span></span>while load_relaxed(flat) == 0 { }
fence_acquire();
print(data); // non-atomic
</pre></div>


<p>This code has a data race and is UB.</p>



<a name="169158356"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169158356" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169158356">(Jun 27 2019 at 17:58)</a>:</h4>
<p>and that's because fences only sync with fences</p>



<a name="169158372"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169158372" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169158372">(Jun 27 2019 at 17:58)</a>:</h4>
<p>but there's just one fence here so nothing it can sync with</p>



<a name="169158417"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169158417" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169158417">(Jun 27 2019 at 17:59)</a>:</h4>
<p>argh ordered my fences wrong again^^ fixing that</p>



<a name="169158456"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169158456" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169158456">(Jun 27 2019 at 17:59)</a>:</h4>
<p>hmm</p>



<a name="169158520"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169158520" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169158520">(Jun 27 2019 at 18:00)</a>:</h4>
<p>you would need to replace the code in thread 2 with an acquire_load to fix the data race</p>



<a name="169158541"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169158541" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169158541">(Jun 27 2019 at 18:00)</a>:</h4>
<p>yes</p>



<a name="169158575"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169158575" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169158575">(Jun 27 2019 at 18:00)</a>:</h4>
<p>that's what I was trying to say</p>



<a name="169158593"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169158593" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169158593">(Jun 27 2019 at 18:00)</a>:</h4>
<p>so a release-acquire store pair has basically the same effect as a release-relaxed-relaxed-aquire store-fence-fence-load quadruple</p>



<a name="169158598"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169158598" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169158598">(Jun 27 2019 at 18:00)</a>:</h4>
<p>but I see your point, in that the relaxed load and stores do not synchronize with anything, its the fences</p>



<a name="169158609"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169158609" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169158609">(Jun 27 2019 at 18:01)</a>:</h4>
<p>but you have to use the same thing "on both sides"</p>



<a name="169158652"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169158652" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169158652">(Jun 27 2019 at 18:01)</a>:</h4>
<p>so can we use "atomic relaxed" as wording for the atomic volatile operations ?</p>



<a name="169158663"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169158663" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169158663">(Jun 27 2019 at 18:01)</a>:</h4>
<p>they don't synchronize with anything</p>



<a name="169158664"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169158664" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169158664">(Jun 27 2019 at 18:01)</a>:</h4>
<p>(and in terms of efficiency, the fences are more likely to "accidentally" synchronize with other things as they are less specific... but then you get better control, like in my example where you get an acquire fence only after the successful read)</p>



<a name="169158674"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169158674" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169158674">(Jun 27 2019 at 18:01)</a>:</h4>
<p>you would need two fences, and then its up to the fences</p>



<a name="169158689"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169158689" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169158689">(Jun 27 2019 at 18:01)</a>:</h4>
<p>no the fence son their own dont do anything</p>



<a name="169158758"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169158758" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169158758">(Jun 27 2019 at 18:02)</a>:</h4>
<p>its the  release-relaxed-relaxed-aquire fence-store-load-fence quadruple that does the synchronization</p>



<a name="169158770"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169158770" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169158770">(Jun 27 2019 at 18:02)</a>:</h4>
<p>and we dont want to include volatile accesses in those</p>



<a name="169158780"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169158780" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169158780">(Jun 27 2019 at 18:02)</a>:</h4>
<p>that's why we cannot call them "relaxed"</p>



<a name="169158803"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169158803" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169158803">(Jun 27 2019 at 18:02)</a>:</h4>
<p>i thought the fences synchronize, and this determines which stores are seen by which loads, etc.</p>



<a name="169158846"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169158846" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169158846">(Jun 27 2019 at 18:03)</a>:</h4>
<p>there's no way to define what it means for two fences to synchronize, in the axiomatic model</p>



<a name="169158895"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169158895" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169158895">(Jun 27 2019 at 18:03)</a>:</h4>
<p>synchronization is ultimately always seeded by a reads-from relationship -- some thread read a thing and thereby observed some other thread's write</p>



<a name="169158920"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169158920" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169158920">(Jun 27 2019 at 18:03)</a>:</h4>
<p>once that happens, <em>sometimes</em> this induces a "synchronizes-with" (which implies happens-before)</p>



<a name="169159015"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169159015" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169159015">(Jun 27 2019 at 18:04)</a>:</h4>
<p>so I always thought of this as the fences synchronize with each other, and that determines which stores happen before which loads</p>



<a name="169159024"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169159024" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169159024">(Jun 27 2019 at 18:04)</a>:</h4>
<p>and that <em>sometimes</em> is</p>
<ul>
<li>either the store was release and the load acquire, then we can a synchronizes-with between the two,</li>
<li>or there was a release-fence program-order-before the store, and an acquire-fence progrm-order after the load, then the fences get a synchronizes-with</li>
</ul>



<a name="169159037"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169159037" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169159037">(Jun 27 2019 at 18:05)</a>:</h4>
<p>for the 2nd clause, the store and load still need to be at least relaxed</p>



<a name="169159053"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169159053" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169159053">(Jun 27 2019 at 18:05)</a>:</h4>
<p>and I'd like to avoid including volatile there</p>



<a name="169159084"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169159084" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169159084">(Jun 27 2019 at 18:05)</a>:</h4>
<p>we have to, otherwise a volatile write can be observed by a relaxed read</p>



<a name="169159109"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169159109" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169159109">(Jun 27 2019 at 18:05)</a>:</h4>
<p>what do you mean?</p>



<a name="169159177"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169159177" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169159177">(Jun 27 2019 at 18:06)</a>:</h4>
<p>for MMIO, it would mean that a non-volatile read was performed</p>



<a name="169159197"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169159197" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169159197">(Jun 27 2019 at 18:06)</a>:</h4>
<blockquote>
<p>so I always thought of this as the fences synchronize with each other, and that determines which stores happen before which loads</p>
</blockquote>
<p>well doing the same thing with non-atomics is still a data race despite the fences, so... that's not quire it in C11 I'm afraid.</p>



<a name="169159202"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169159202" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169159202">(Jun 27 2019 at 18:06)</a>:</h4>
<p>as in, if you are doing MMIO, the reads and the writes must be volatile, or UB probably</p>



<a name="169159210"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169159210" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169159210">(Jun 27 2019 at 18:06)</a>:</h4>
<p>no I mean what do we have to do and why can who observe what if we dont?^^</p>



<a name="169159271"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169159271" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169159271">(Jun 27 2019 at 18:07)</a>:</h4>
<p>i mean that if we say that a volatile store is atomic relaxed, then a non-volatile relaxed load in another thread would be ok, depending on fences</p>



<a name="169159297"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169159297" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169159297">(Jun 27 2019 at 18:07)</a>:</h4>
<p>but we probably want to make that "not ok", and require the load to be volatile as well</p>



<a name="169159332"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169159332" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169159332">(Jun 27 2019 at 18:07)</a>:</h4>
<p>and also prevent people from using volatile for intra-thread synchronization</p>



<a name="169159360"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169159360" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169159360">(Jun 27 2019 at 18:08)</a>:</h4>
<p>yes. in fact I'd say <em>even if</em> the load is also volatile, it should still yield <code>undef</code> as this is a data race</p>



<a name="169159392"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169159392" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169159392">(Jun 27 2019 at 18:08)</a>:</h4>
<p>yes</p>



<a name="169159402"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169159402" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169159402">(Jun 27 2019 at 18:08)</a>:</h4>
<p>the exemption from data races is just for UB-ness, not for whether they happen</p>



<a name="169159414"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169159414" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169159414">(Jun 27 2019 at 18:08)</a>:</h4>
<p>the docs should probably say that^^</p>



<a name="169159449"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169159449" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169159449">(Jun 27 2019 at 18:08)</a>:</h4>
<p>well... if we use freeze, undef will never be returned</p>



<a name="169159473"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169159473" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169159473">(Jun 27 2019 at 18:08)</a>:</h4>
<p>yes but that's still very different from the normal atomic relaxed</p>



<a name="169159478"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169159478" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169159478">(Jun 27 2019 at 18:08)</a>:</h4>
<p>which returns the old or the new value</p>



<a name="169159485"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169159485" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169159485">(Jun 27 2019 at 18:09)</a>:</h4>
<p>well its not atomic</p>



<a name="169159515"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169159515" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169159515">(Jun 27 2019 at 18:09)</a>:</h4>
<p>so you are not guaranted either the old or the new, you can get something in between</p>



<a name="169159516"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169159516" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169159516">(Jun 27 2019 at 18:09)</a>:</h4>
<p>if its relaxed its atomic, otherwise the term makes no sense^^</p>



<a name="169159554"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169159554" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169159554">(Jun 27 2019 at 18:09)</a>:</h4>
<blockquote>
<p>so you are not guaranted either the old or the new, you can get something in between</p>
</blockquote>
<p>you can get anything. I've been told about weird compiler optimizations where you can even see values that never were there</p>



<a name="169159564"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169159564" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169159564">(Jun 27 2019 at 18:09)</a>:</h4>
<p>this can occur due to reorderings</p>



<a name="169159588"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169159588" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169159588">(Jun 27 2019 at 18:10)</a>:</h4>
<p>well volatile cannot be reordered around volatile</p>



<a name="169159634"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169159634" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169159634">(Jun 27 2019 at 18:10)</a>:</h4>
<p>they were never there in the source program but reorderdings make them "be there" in the assembly</p>



<a name="169159677"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169159677" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169159677">(Jun 27 2019 at 18:10)</a>:</h4>
<p>but the non-atomic write from which this volatile read reads is subject to all optimizations</p>



<a name="169159713"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169159713" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169159713">(Jun 27 2019 at 18:10)</a>:</h4>
<p>so we cant guarantee that you wlll only read a combination of the values you have written</p>



<a name="169159747"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169159747" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169159747">(Jun 27 2019 at 18:11)</a>:</h4>
<p>maybe if <em>all</em> accesses to this location are volatile... but why would we want a special case for that?</p>



<a name="169159785"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169159785" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169159785">(Jun 27 2019 at 18:11)</a>:</h4>
<p>well C kind of does</p>



<a name="169159802"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169159802" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169159802">(Jun 27 2019 at 18:11)</a>:</h4>
<p>the data is volatile, not the accesses</p>



<a name="169159837"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169159837" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169159837">(Jun 27 2019 at 18:11)</a>:</h4>
<p>some of the proposals that are linked are suggesting to change that, IIRC</p>



<a name="169159847"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169159847" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169159847">(Jun 27 2019 at 18:11)</a>:</h4>
<p>also LLVM doesnt work that way</p>



<a name="169159892"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169159892" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169159892">(Jun 27 2019 at 18:12)</a>:</h4>
<p>and IMO LLVM's model is better</p>



<a name="169159922"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169159922" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169159922">(Jun 27 2019 at 18:12)</a>:</h4>
<p>also "de-facto C" has a notion of volatile accesses and the Linux kernel and many more programs rely on that to work</p>



<a name="169159944"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169159944" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169159944">(Jun 27 2019 at 18:12)</a>:</h4>
<p>the C standard basically just ignores reality here</p>



<a name="169160015"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169160015" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169160015">(Jun 27 2019 at 18:13)</a>:</h4>
<p>so are volatile reads/writes to the same memory from different threads without synchronization UB ?</p>



<a name="169160031"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169160031" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169160031">(Jun 27 2019 at 18:13)</a>:</h4>
<p>i feel am back to square 1 :D</p>



<a name="169160039"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169160039" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169160039">(Jun 27 2019 at 18:13)</a>:</h4>
<p>so, anyone, coming back to your proposal... (a) please avoid the term "relaxed", and (b) when you say there are no data races, maybe it's better to say that data races are <em>not</em> UB but return initialized data?</p>



<a name="169160059"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169160059" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169160059">(Jun 27 2019 at 18:14)</a>:</h4>
<p>that's for volatile reads</p>



<a name="169160168"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169160168" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169160168">(Jun 27 2019 at 18:14)</a>:</h4>
<p>what to do about stores... not sure. write-write races are UB in LLVM, so if we want two concurrent volatile writes to the same location NOT UB, we'd have to ask LLVM first to give us better guarantees.</p>



<a name="169160202"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169160202" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169160202">(Jun 27 2019 at 18:15)</a>:</h4>
<blockquote>
<p>so are volatile reads/writes to the same memory from different threads without synchronization UB ?</p>
</blockquote>
<p>the read vs write thing makes a difference here ;) if both are writes, dunno (yes if you ask the LLVM LangRef). otherwise (if at least one is a read), no.</p>



<a name="169160401"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169160401" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169160401">(Jun 27 2019 at 18:17)</a>:</h4>
<p>is that true for volatile writes as well?</p>



<a name="169160422"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169160422" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169160422">(Jun 27 2019 at 18:17)</a>:</h4>
<p>I have not seen an exception for volatile writes</p>



<a name="169160472"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169160472" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169160472">(Jun 27 2019 at 18:18)</a>:</h4>
<p>nor for volatile reads, btw -- in LLVM, reads never cause UB due to data races</p>



<a name="169160478"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169160478" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169160478">(Jun 27 2019 at 18:18)</a>:</h4>
<p>they just return <code>undef</code></p>



<a name="169215342"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169215342" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169215342">(Jun 28 2019 at 11:06)</a>:</h4>
<p>so I was wondering if we should say that volatile load / stores have side-effects / are unknown functions at all</p>



<a name="169215444"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169215444" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169215444">(Jun 28 2019 at 11:08)</a>:</h4>
<div class="codehilite"><pre><span></span><span class="kd">let</span><span class="w"> </span><span class="n">a</span>: <span class="nc">ptr</span><span class="p">;</span><span class="w"></span>
<span class="kd">let</span><span class="w"> </span><span class="n">b</span>: <span class="nc">ptr</span><span class="p">;</span><span class="w"></span>
<span class="n">assert_ne</span><span class="o">!</span><span class="p">(</span><span class="n">a</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="kt">usize</span><span class="p">,</span><span class="w"> </span><span class="n">b</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="kt">usize</span><span class="p">);</span><span class="w"></span>
<span class="kd">let</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">a</span><span class="p">.</span><span class="n">read_volatile</span><span class="p">();</span><span class="w"></span>
<span class="kd">let</span><span class="w"> </span><span class="n">y</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">b</span><span class="p">.</span><span class="n">read</span><span class="p">();</span><span class="w"></span>
</pre></div>


<p>LLVM is allowed to re-order the <code>b.read()</code> before the <code>a.read_volatile()</code> AFAICT</p>



<a name="169215455"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169215455" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169215455">(Jun 28 2019 at 11:08)</a>:</h4>
<p>if <code>read_volatile</code> was an unknown function or had unknown side-effects, this isn't possible, because those side-effects could modify the memory at <code>b</code> (and the re-ordering would change program semantics).</p>



<a name="169215470"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169215470" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169215470">(Jun 28 2019 at 11:09)</a>:</h4>
<p>so what we really want to say is that the compiler must emit volatile loads and stores, and that these cannot be re-ordered across other volatile loads/stores</p>



<a name="169215533"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169215533" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169215533">(Jun 28 2019 at 11:10)</a>:</h4>
<p>and just leave it as that</p>



<a name="169217387"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169217387" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169217387">(Jun 28 2019 at 11:45)</a>:</h4>
<p>I've updated the gist with write operations: <a href="https://gist.github.com/gnzlbg/c8ef62c12e692a420face245c5df7123" target="_blank" title="https://gist.github.com/gnzlbg/c8ef62c12e692a420face245c5df7123">https://gist.github.com/gnzlbg/c8ef62c12e692a420face245c5df7123</a></p>



<a name="169239953"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169239953" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169239953">(Jun 28 2019 at 16:27)</a>:</h4>
<blockquote>
<p>if <code>read_volatile</code> was an unknown function or had unknown side-effects, this isn't possible, because those side-effects could modify the memory at <code>b</code> (and the re-ordering would change program semantics).</p>
</blockquote>
<p>that's why I wrote, when I specified volatile, that they are unknown function calls that LLVM may make assumptions about. namely... &lt;finding my own post to copy-paste&gt;</p>



<a name="169239998"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169239998" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169239998">(Jun 28 2019 at 16:27)</a>:</h4>
<blockquote>
<p>"doesn't mutate any memory I know about that is not aliased with x..x+size"</p>
</blockquote>
<p>("I" = the compiler)</p>



<a name="169240064"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169240064" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169240064">(Jun 28 2019 at 16:28)</a>:</h4>
<p>probably even stronger, doesn't <em>access</em> that memory</p>



<a name="169240101"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169240101" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169240101">(Jun 28 2019 at 16:28)</a>:</h4>
<p>but if you want to avoid that, please still talk about them being externally observable events</p>



<a name="169240132"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169240132" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169240132">(Jun 28 2019 at 16:28)</a>:</h4>
<p>such that they cannot be reordered wrt other externally obsevrable events -- in particular, other volatile accesses</p>



<a name="169240160"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch%20volatile%20operations/near/169240160" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/arch.20volatile.20operations.html#169240160">(Jun 28 2019 at 16:29)</a>:</h4>
<p>but also syscalls</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>